/**
 * Created by King_Vicent on 2018/7/7.
 */
var trendsChart = echarts.init(document.getElementById('trends-charts')) // 督察趋势
var ProblemChart = echarts.init(document.getElementById('problem-charts')) // 问题分类
var superviseChart = echarts.init(document.getElementById('supervise-charts')) // 督察数据
//var rectifyChart = echarts.init(document.getElementById('rectify-charts')) // 整改情况
var noticeType = false; // true:通知通报  false:指令信息
var noticTempData = [];
$(function () {

    //常用功能
    getAlwaysUse();

    // var trendsView = $('#trends-area-select').val()
    // var problemView = $('#problem-area-select').val()
    var superviseView = $('#supervise-area-select').val()
    // var rectifyView = $('#rectify-area-select').val()

    /*$('.changeType').on('click', '.type-radio' ,function () {
     if ($('.type1').is(":visible")) {
     $('.type1').hide()
     $('.type2').show()
     // 调用接口 获取数据
     getInstructionList();
     } else {
     $('.type2').hide()
     $('.type1').show()
     // 调用接口 获取数据
     getNoticeList();
     }
     })

     $('.type2').hide()
     $('.type1').show()
     // 调用接口 获取数据
     getNoticeList();*/

    //天
    getTrendChart()
    //本周
    getProblemChart()
//    getRectifyChart()
//    getYearDeptQuestionCount()
    getSuperviseChart(superviseView)
    getNoticeList();
    getXzqhSelect(0);
    // 选择时间 督察趋势
    /*$('.content-middle .date-type-item button').click(function () {
        var val = $(this).val()
        $(this).parent('.date-type-item').addClass('active')
        $(this).parent('.date-type-item').siblings().removeClass('active')
        dateType = val
        getTrendChart()
    })*/
     $('#date-type-item').change(function () {
            var val = $(this).val()
//            $(this).parent('.date-type-item').addClass('active')
//            $(this).parent('.date-type-item').siblings().removeClass('active')
            dateType = val
            getTrendChart()
        })
    $('#messageMore').click(function () {
    	if(noticeType){
    		//location = '../../../modules/business/tztb.html';
    		parent.alwayUseHref('modules/business/tztb.html')
    	}else{
    		//location = '../../../modules/business/xzzl.html';
    		parent.alwayUseHref('modules/business/xzzl.html')
    	}
    });

    // 选择时间 其他
    $('.charts-date-select').on('change', function () {
        var val = $(this).val()
        var selectDateId = $(this).attr('id')
        switch (selectDateId) {
            case 'trends-date-select' :
                // getTrendChart(8 - val)
                // console.log('trends-date-select：' + (8 - val))
                break
            case 'problem-date-select' :
                problemView = val
                getProblemChart()
                console.log('problem-date-select：' + (8 - val))
                break
            case 'supervise-date-select' :
                getSuperviseChart(8 - val)
                console.log('supervise-date-select：' + (8 - val))
                break
            default:
                rectifyView = val
//                getRectifyChart()
                console.log('rectify-date-select：' + (8 - val))
        }
    })

    //选择地区
    $('.charts-area-select').on('change', function () {
        var val = $(this).val()
        var selectAreaId = $(this).attr('id')
        switch (selectAreaId) {
            case 'trends-area-select' :

                if (val < 0) {
                    getTrendChart(0)
                    getXzqhNullSelect("trends-area-select-city")
                    getXzqhNullSelect("trends-area-select-area")
                } else {
                    getTrendChart(val)
                    getXzqhSelect(val, "trends-area-select-city")
                    getXzqhNullSelect("trends-area-select-area")
                }

                // console.log('trends-area-select：' + (8 - val))
                break
            case 'trends-area-select-city' :
                if (val < 0) {
                    getTrendChart($("#trends-area-select").val())
                    getXzqhNullSelect("trends-area-select-area")
                } else {
                    getTrendChart(val)
                    getXzqhSelect(val, "trends-area-select-area")
                }
                // console.log('trends-area-select：' + (8 - val))
                break
            case 'trends-area-select-area' :

                if (val < 0) {
                    getTrendChart($("#trends-area-select-city").val())
                } else {
                    getTrendChart(val)
                }
                // getXzqhSelect(val,"trends-area-select-area")
                // console.log('trends-area-select：' + (8 - val))
                break
            case 'problem-area-select' :
                if (val < 0) {
                    getProblemChart(0)
                    getXzqhNullSelect("problem-area-select-city")
                    getXzqhNullSelect("problem-area-select-area")
                } else {
                    getProblemChart(val)
                    getXzqhSelect(val, "problem-area-select-city")
                    getXzqhNullSelect("problem-area-select-area")
                }

                // console.log('problem-area-select：' + (8 - val))
                break
            case 'problem-area-select-city' :

                if (val < 0) {
                    getProblemChart($("#problem-area-select").val())
                    getXzqhNullSelect("problem-area-select-area")
                } else {
                    getProblemChart(val)
                    getXzqhSelect(val, "problem-area-select-area")
                }
                // console.log('problem-area-select：' + (8 - val))
                break
            case 'problem-area-select-area' :

                if (val < 0) {
                    getProblemChart($("#problem-area-select-city").val())
                } else {
                    getProblemChart(val)
                }
                // getXzqhSelect(val,"problem-area-select")
                // console.log('problem-area-select：' + (8 - val))
                break
            case 'supervise-area-select' :
                // getSuperviseChart(val)
                // getXzqhSelect(val,"supervise-area-select-city")
                if (val < 0) {
                    getSuperviseChart(0)
                    getXzqhNullSelect("supervise-area-select-city")
                    getXzqhNullSelect("supervise-area-select-area")
                } else {
                    getSuperviseChart(val)
                    getXzqhSelect(val, "supervise-area-select-city")
                    getXzqhNullSelect("supervise-area-select-area")
                }
                // console.log('supervise-area-select：' + (8 - val))
                break
            case 'supervise-area-select-city' :
                // getSuperviseChart(val)
                // getXzqhSelect(val,"supervise-area-select-area")
                if (val < 0) {
                    getSuperviseChart($("#supervise-area-select").val())
                    getXzqhNullSelect("supervise-area-select-area")
                } else {
                    getSuperviseChart(val)
                    getXzqhSelect(val, "supervise-area-select-area")
                }
                // console.log('supervise-area-select：' + (8 - val))
                break
            case 'supervise-area-select-area' :
                // getSuperviseChart(val)
                if (val < 0) {
                    getSuperviseChart($("#supervise-area-select-city").val())
                } else {
                    getSuperviseChart(val)
                }
                // getXzqhSelect(val,"supervise-area-select")
                // console.log('supervise-area-select：' + (8 - val))
                break
            case 'rectify-area-select' :
                // getRectifyChart( val)
                // getXzqhSelect(val,"rectify-area-select-city")
                if (val < 0) {
//                    getRectifyChart(0)
                    getXzqhNullSelect("rectify-area-select-city")
                    getXzqhNullSelect("rectify-area-select-area")
                } else {
//                    getRectifyChart(val)
                    getXzqhSelect(val, "rectify-area-select-city")
                    getXzqhNullSelect("rectify-area-select-area")
                }
                // console.log('supervise-area-select：' + (8 - val))
                break
            case 'rectify-area-select-city' :
                // getRectifyChart( val)
                // getXzqhSelect(val,"rectify-area-select-area")
                if (val < 0) {
//                    getRectifyChart($("#rectify-area-select").val())
                    getXzqhNullSelect("rectify-area-select-area")
                } else {
//                    getRectifyChart(val)
                    getXzqhSelect(val, "rectify-area-select-area")
                }
                // console.log('supervise-area-select：' + (8 - val))
                break
            default:
                // getRectifyChart( val)
                if (val < 0) {
//                    getRectifyChart($("#rectify-area-select-city").val())
                } else {
//                    getRectifyChart(val)
                }
            // getXzqhSelect(val,"rectify-area-select")
            // console.log('rectify-area-select：' + (8 - val))
        }
    })

})

/**
 * 趋势视图 trendsView 折线图
 *
 * @param dateType 统计方式 4 年 3 月  2 周  1 日
 * @param zoning 区划
 */
var dateType = 1;

function getTrendChart(zoning) {
    var url = '../business/homeStatistics/trendsView'
    var params = {};
    //两个值都没取到
    params.dateType = dateType
    params.xzqhId = zoning
    $.ajax({
        // url: '../../../statics/json/homepage.json',
        type: "POST",
        url: baseURL + url,
        contentType: "application/json",
        data: JSON.stringify(params),
        success: function (res) {
            // res = JSON.parse(res)
            var seriesData = []
// console.log(res)
            if (dateType == 4) {
                var data = [];
                for (var i = 0; i < res.length; i++) {


                    for (var j = 0; j < res[i].list.length; j++) {
                        var year = res[i].list[j].yearDate + "/1/1";
                        var value = {
                            name: res[i].key,
                            value: [year, res[i].list[j].countNum]
                        }
                        data.push(value)
                    }
                }
                var series = {
                    // name: "2",
                    type: 'line',
                    smooth: true,
                    itemStyle: {
                        normal: {
                            color: "#75B3FF",
                            lineStyle: {
                                color: "#75B3FF"
                            }
                        }
                    },
                    // showSymbol: false,
                    // hoverAnimation: false,
                    data: data
                }
                seriesData = []
                seriesData.push(series)
            } else {
                for (var i = 0; i < res.length; i++) {
                    var data = [];

                    for (var j = 0; j < res[i].list.length; j++) {
                        var date = new Date(res[i].list[j].createTime);
                        /*  if (dateType == 4) {
                         date = res[i].list[j].createTime;
                         }*/
                        if (dateType == 3) {
                            date = 2017 + "/" + (date.getMonth() + 1) + "/" + date.getDate();
                        }
                        if (dateType == 2) {
                            date = 2017 + "/" + (date.getMonth() + 1) + "/" + date.getDate();
                        }
                        if (dateType == 1) {
                            date = 2017 + "/" + (date.getMonth() + 1) + "/" + date.getDate();
                        }
                        var value = {
                            name: res[i].key,
                            value: [date, res[i].list[j].countNum]
                        }

                        data.push(value)
                    }
                    var series = {
                        name: res[i].key,
                        type: 'line',
                        smooth: true,
                        itemStyle: {
                            normal: {
                                color: "#75B3FF",
                                lineStyle: {
                                    color: "#75B3FF"
                                }
                            }
                        },
                        // showSymbol: false,
                        // hoverAnimation: false,
                        data: data
                    }

                    seriesData.push(series)

                    // xData.push(res.rows[i].key.slice(5))
                }
            }
            var legend = {show:false}
//            if (dateType == 4) {
//                legend.show = false
//            } else {
//                legend.show = true
//            }
            trendsChart.setOption({
                legend: legend,

                tooltip: {
                    trigger: 'axis',
                    formatter: function (params) {
                        params = params[0];
                        var date = new Date(params.value[0]);
                        if (dateType == 4) {
                            return params.value[1] + "例问题<br/>" + "&nbsp;" + date.getFullYear() + "年";
                        }
                        if (dateType == 3) {
                            return params.value[1] + "例问题<br/>" + (date.getMonth() + 1) + '月,' + params.name;
                        }
                        if (dateType == 2) {
                            var firstDay = new Date(date.getFullYear(), 0, 1);
                            var d = Math.ceil((date.valueOf() - firstDay.valueOf()) / 86400000);
                            var result = Math.ceil(d / 7);
                            return params.value[1] + "例问题<br/>第" + (result + 1) + '周,' + params.name;
                        }
                        /*   if(dateType=='1'){
                         return "&nbsp;&nbsp;&nbsp;"+params.value[1]+"例问题<br/>" + (date.getMonth() + 1) + '月' + date.getDate() + '日,'+params.name  ;
                         }*/
                        return "&nbsp;&nbsp;&nbsp;" + params.value[1] + "例问题<br/>" + (date.getMonth() + 1) + '月' + date.getDate() + '日,' + params.name;

                    },
                    axisPointer: {
                        animation: false
                    }
                },
                xAxis: {
                    type: 'time',
                    splitLine: {
                        show: false
                    },

                    axisLine: {
                        show: true,
                        lineStyle: {
                            color: "#999999",
                            width: 1,
                            type: "solid"
                        }
                    },
                    axisLabel: {
                        show: true,
                        textStyle: {
                            color: "#666666",
                        },
                        // 使用函数模板，函数参数分别为刻度数值（类目），刻度的索引
                        formatter: function (value, index) {
                            // 格式化成月/日，只在第一个刻度显示年份
                            var date = new Date(value);
                            var texts = (date.getMonth() + 1) + "月" + date.getDate() + "日";
                            if (dateType == 4) {
                                texts = date.getFullYear() + "年";
                            }
                            if (dateType == 3) {
                                texts = (date.getMonth() + 1) + "月";
                            }
                            if (dateType == 2) {
                                var firstDay = new Date(date.getFullYear(), 0, 1);
                                var d = Math.ceil((date.valueOf() - firstDay.valueOf()) / 86400000);
                                var result = Math.ceil(d / 7);
                                texts = "第" + (result + 1) + "周";
                            }

                            /* if (index === 0) {
                             texts.unshift(date.getYear());
                             }*/
                            return texts;
                        }
                    }
                },
                yAxis: {
                    type: 'value',
                    boundaryGap: [0, '100%'],
                    splitLine: {
                        show: true,
                        lineStyle: {
                            color: "#E6E6E6",
                        }
                    }
                },
                axisLine: {
                    show: true,
                    lineStyle: {
                        color: "#999999",
                        width: 1,
                        type: "solid"
                    },
                },
                axisLabel: {
                    show: true,
                    textStyle: {
                        color: "#666666",
                    },
                },
                series: seriesData,
                grid:{
                    x:'30px',
                    y:'50px'
                }
            }, true);
        }
    })
}


var problemView = 1
//环形图
function getProblemChart(zoning) {
    var problemData = new Array()
    // problemView 为ajax查询参数，查询结果赋值给problemData，然后再图里画出来
    var url = '../business/homeStatistics/problemChartAnnular'
    var params = {};
    //两个值都没取到
    params.dateType = problemView
    params.xzqhId = zoning
    $.ajax({
        type: "POST",
        async: false,
        url: baseURL + url,
        contentType: "application/json",
        data: JSON.stringify(params),
        success: function (res) {
            problemData = res;
        }
    })
    // problemData = [
    //     {
    //         value: 2154,
    //         name: '队伍问题'
    //     }, {
    //         value: 3854,
    //         name: '其他问题'
    //     }, {
    //         value: 3515,
    //         name: '执法问题'
    //     }
    // ]
    var total = 0
    var legendData = []
    if (problemData.length > 0) {
        problemData.forEach(function (value, index, array) {
            total += parseInt(value.value)
            legendData.push(value.name)
        })
    }
    
//region    根据空格与数字位数关系，得出居中算法
//    1,7
//    2,6
//    3,5
    var empty = "";
    for(var i=0;i<8-(total.toString().length);i++){
        empty+=" ";
    }
    total = empty+total;
//endregion
    option = {
        title: {
            text: total,
            x: '17%',
            y: '45%',
            padding: [0, 0],
            align: 'center',
            textStyle: {
                color: '#E16950',
                fontSize: 18,
            },
            subtext: '发现问题总数',
            subtextStyle: {
                color: '#666666',
                fontSize: 16,
            },
        },
        tooltip: {
            trigger: 'item',
            formatter: "{a} <br/><br/>{b}： {c} ({d}%)",
        },
        legend: {
            selectedMode: false,
            orient: 'vertical',
            x: '70%',
            y: 'center',
            data: legendData,
            itemGap: 8,
            icon: 'circle',
            formatter: function (name) {
                var total = 0
                var target = 0;
                for (var i = 0, l = problemData.length; i < l; i++) {
                    total += parseInt(problemData[i].value)
                    if (problemData[i].name == name) {
                        target = problemData[i].value
                    }
                }
                var arr = [
                    '{b|' + name + '}',
                    '{b|' + (total==0?0:((parseInt(target) / parseInt(total)) * 100).toFixed(2)) + '%}',
                    '{hr|}'
                ]
                return arr.join('  ')
            },
            textStyle: {
                rich: {
                    a: {
                        fontSize: 14,
                        verticalAlign: 'top',
                        align: 'center',
                        padding: [0, 0, 2, 0],
                        color: '#333'
                    },
                    b: {
                        fontSize: 14,
                        align: 'center',
                        padding: [0, 0, 0, 0],
                        lineHeight: 20,
                        color: '#777'
                    }
                }
            }
        },
        series: [{
            name: '发现问题总数',
            type: 'pie',
            radius: ['60%', '63%'],
            center: ['28%', '50%'],
            hoverAnimation: false,
            color: ['#A4CDFF', '#FFD1A4', '#D9FFA4','#A4FFF3','#A4B7FF','#CAA4FF','#FFA4C6'],
            label: {
                normal: {
                    show: false
                },
            },
            data: problemData
        }]
    }
    ProblemChart.setOption(option, true)
}

// 柱状图
function getSuperviseChart(superviseView) {
    var superviseData = new Array()

        superviseData = [
            {
                value: 2154,
                name: '1238投诉'
            }, {
                value: 3854,
                name: '现场督察'
            }, {
                value: 3515,
                name: '网上督察'
            }, {
                value: 1999,
                name: '信访系统'
            }, {
                value: 5135,
                name: '日志审计'
            }
        ]
        var yMax = 6000;
    var dataShadow = [];

    for (var i = 0; i < superviseData.length; i++) {
        dataShadow.push(yMax);
    }
        var xData = new Array()
        var yData = new Array()
        superviseData.forEach(function (value, index, array) {
            xData.push(value.name)
            yData.push(value.value)
        })
        option = {
            grid: {
                left: '3%',
                right: '4%',
                bottom: '3%',
                containLabel: true,

            },
            xAxis: [{
                show:true,
                type: 'category',
                data: xData,
                // splitNumber:1,
                axisLine: {
                    show: true,
                    lineStyle: {
                        color: "#999999",
                        width: 1,
                        type: "solid"
                    }
                },
                axisTick: {
                    show: false
                },
                axisLabel: {
                    show: true,
                    textStyle: {
                        color: "#666666",
                    }
                },
            }],
            yAxis: [{
                type: 'value',

                axisLine: {
                    show: true,
                    lineStyle: {
                        color: "#999999",
                        width: 1,
                        type: "solid"
                    },
                },
                axisTick: {
                    show: true
                },
                axisLabel: {
                    show: true,
                    textStyle: {
                        color: "#666666",
                    }
                },
                splitLine: {
                    show:false,
                    lineStyle: {
                        color: "#666666",
                    }
                }
            }],
            tooltip: {
                trigger: "item",
                backgroundColor: "#75B3FF ",
                textStyle: {
                    color: "#ffffff",
                    fontSize: 16
                },
                formatter: function (name) {
                    var total = 0
                    var target
                    for (var i = 0, l = superviseData.length; i < l; i++) {
                        total += superviseData[i].value
                        if (superviseData[i].name == name.name) {
                            target = superviseData[i].value
                        }
                    }
                    var percent = ((target / total) * 100).toFixed(2) + '%'
                    return percent
                },
            },
            series: [
                { // For shadow
                type: 'bar',
                itemStyle: {
                    // emphasis: {barBorderRadius: 30},
                    normal: {color:'rgba(117, 179, 255,0.1)' ,
                    barBorderRadius:[10, 10, 0, 0]},
                },

                barWidth: 20,
                barGap:'-100%',
                barCategoryGap:'40%',
                data: dataShadow,
                animation: true
            },
                {
                type: 'bar',
                data: yData,
                barWidth: 20,
                itemStyle: {
                    normal: {
                        color: "#75B3FF",
                    barBorderRadius:[10, 10, 0, 0],
                        opacity: 1,
                    }
                }
            }]
    }
    superviseChart.setOption(option)
}

var rectifyView = 1;
// 半环图
function getRectifyChart(zoning) {debugger;
    var rectifyData = new Array()
    // rectifyView 为ajax查询参数，rectifyData，然后再图里画出来
    var url = '../business/homeStatistics/rectifyChartSemiRing'
    var params = {};
    //两个值都没取到
    params.dateType = rectifyView
    params.xzqhId = zoning
    //计算总和
    var dataCount = 0
    $.ajax({
        type: "POST",
        async: false,
        url: baseURL + url,
        contentType: "application/json",
        data: JSON.stringify(params),
        success: function (res) {
            // rectifyData = res;
            rectifyData = [
                {
                    value: res[0].rectificationCount,
                    name: '已整改'
                }, {
                    value: res[0].noRectificationCount,
                    name: '未整改'
                }
            ]
            dataCount = res[0].allCount
        }
    })

    /*
     for (var i = 0; i < rectifyData.length; i++) {
     dataCount +=  parseInt(rectifyData[i].value)
     }*/
    //添加新的元素到data中，并设置其颜色样式为白色
    rectifyData.push({value: dataCount, name: '问题总数', itemStyle: {normal: {color: 'rgba(0,0,0,0)'}}})
    option = {
        title: {
            text: dataCount,
            right: '5%',
            bottom: '5%',
            padding: [24, 0],
            align: 'center',
            textStyle: {
                color: '#CD061B',
                fontSize: 20,
                align: 'center'
            },
            subtext: '问题总数',
            subtextStyle: {
                color: '#898989',
                fontSize: 12,
                align: 'center'
            },
        },
        tooltip: {
            formatter: "{a} <br/>{b} : {c}"
        },
        series: [{
            //类型
            type: 'gauge',
            //半径
            radius: 180,
            //起始角度。圆心 正右手侧为0度，正上方为90度，正左手侧为180度。
            startAngle: 180,
            //结束角度。
            endAngle: 0,
            center: ['45%', '85%'],
            //仪表盘轴线相关配置。
            axisLine: {
                show: true,
                // 属性lineStyle控制线条样式
                lineStyle: {
                    width: 50,
                    color: [
                        [rectifyData[0].value / dataCount, '#E26850'],
                        [1, '#e9e9e9']
                    ]
                }
            },
            //分隔线样式。
            splitLine: {
                show: false,
            },
            //刻度样式。
            axisTick: {
                show: false,
            },
            //刻度标签。
            axisLabel: {
                show: false,
            },
            //仪表盘指针。
            pointer: {
                show: false,
                //指针长度
                length: '90%',
                width: 0,
            },
            //仪表盘标题。
            //仪表盘标题。
            title: {
                show: true,
                offsetCenter: [0, '-8%'], // x, y，单位px
                textStyle: {
                    color: '#9D9D9D',
                    fontSize: 16
                },
            },
            //仪表盘详情，用于显示数据。
            detail: {
                show: true,
                offsetCenter: [0, '-25%'],
                formatter: '{value}',
                textStyle: {
                    color: '#333',
                    fontSize: 34
                }
            },
            data: [{
                value: rectifyData[0].value,
                name: '已整改',
            }]
        }]
    }
//    rectifyChart.setOption(option)
}

function getNoticeList() {
    if (noticeType) {
        // 若当前已经是通知通报,就不用请求了
        return
    }
    $.ajax({
        url: '../../../business/messagenotic/noticlist',
        type: 'post',
        dataType: 'json',
        data: {
            'sidx': 'create_time',
            'order': 'desc',
            'deleteFlag': '0',
            'limit': 8
        },
        success: function (result) {
            noticeType = !noticeType;
            $("#zlxx").removeClass("choseActive");
            $("#titleByNotic").text('通知通报');
            $("#tztb").addClass("choseActive");
            var html = '';
            if (result.code == '0') {
                var data = result.data;
                for (var i = 0; i < data.length; i++) {
                    html += '<li class="message-item clearfix" onclick="msgDetail(\'tztb\',' + data[i].id + ')"><span class="title-left">';
                    if (null != data[i].isTop && data[i].isTop == '1') {
                        html += '<label class="top-tag">置顶</label>';
                    }
                    html += data[i].xxtgmc + '</span>';
                    html += '<span class="title-right">' + dateFtt('yyyy-MM-dd', new Date(data[i].createTime)) + '</span>';
                    html += '</li>';
                }
                noticTempData = data;
            }else{
            	noticTempData = [];
            }
            $("#noticlist").html(html);
        }
    })
}

function getInstructionList() {
    if (!noticeType) {
        // 若当前已经是指令信息,就不用请求了
        return
    }
    $.ajax({
        url: '../../../business/instructions/instructionlist',
        type: 'post',
        dataType: 'json',
        data: {
            'sidx': 'create_time',
            'order': 'desc',
            'deleteFlag': '0',
            'limit': 8
        },
        success: function (result) {
            noticeType = !noticeType;
            $("#tztb").removeClass("choseActive");
            $("#titleByNotic").text('指令信息');
            $("#zlxx").addClass("choseActive");
            var html = '';
            if (result.code == '0') {
                var data = result.data.list;
                for (var i = 0; i < data.length; i++) {
                    //html += '<li class="message-item clearfix"><span class="title-left">';
                    html += '<li class="message-item clearfix" onclick="msgDetail(\'zl\',' + data[i].id + ')"><span class="title-left">';
                    /*if (null != data[i].isTop && data[i].isTop == '1') {
                     html += '<label class="top-tag">置顶</label>';
                     }*/
                    html += data[i].titleName + '</span>';
                    html += '<span class="title-right">' + dateFtt('yyyy-MM-dd', new Date(data[i].createTime)) + '</span>';
                    html += '</li>';
                }
                noticTempData = data;
            }else{
            	noticTempData = [];
            }
            $("#noticlist").html(html);
        }
    })
}

/**
 * 获取今年的单位问题统计 首次和二次整改统计
 * @param zoning 区划
 */
function getYearDeptQuestionCount(zoning) {
    var url = '../business/homeStatistics/yearDeptQuestionCount'
    var params = {};
    //两个值都没取到
    // params.dateType = rectifyView
    params.xzqhId = zoning

    //计算总和
    $.ajax({
        type: "POST",
        async: false,
        url: baseURL + url,
        contentType: "application/json",
        data: JSON.stringify(params),
        success: function (res) {
            $(".eczg").text(((parseInt(res[0].twoFrequency) * 1.0 / parseInt(res[0].allCount)) * 100).toFixed(2))
            $(".sczg").text(((parseInt(res[0].oneFrequency) * 1.0 / parseInt(res[0].allCount)) * 100).toFixed(2))
        }
    })
}

function getXzqhNullSelect(id) {
    var html = " <option value=\"-1\">全部</option>"
    $("#" + id).html(html)
}
function getXzqhSelect(parentId, id) {
    if (parentId < 0) {
        return
    }
    var url = '../business/sysxzqh/findXzqhByParentId'
    var params = {};
    //两个值都没取到
    params.parentId = parentId
    //计算总和
    $.ajax({
        type: "POST",
        async: false,
        url: baseURL + url,
        // contentType: "application/json",
        data: params,
        success: function (res) {
            if (res.code === '0') {
                // console.log(res.list)
                var html = " <option value=\"-1\">全部</option>"

                if (res.list != null && res.list.length > 0) {
                    for (var i = 0, len = res.list.length; i < len; i++) {
                        html += " <option value=\"" + res.list[i].xzqhId + "\">" + res.list[i].name + "</option>"
                    }
                }
                if (id != undefined && id != null && id != "") {
                    $("#" + id).html(html)
                } else {
                    $("#trends-area-select").html(html)

                    $("#problem-area-select").html(html)
                    $("#supervise-area-select").html(html)
                    $("#rectify-area-select").html(html)
                }

            } else {
                alert(res.msg);
            }

        }
    })
    /* var url = '../business/sysxzqh/list'
     // var params = {};
     //两个值都没取到
     // params.dateType = rectifyView
     //计算总和
     $.ajax({
     type: "POST",
     async:false,
     url: baseURL + url,
     contentType: "application/json",
     // data: JSON.stringify(params),
     success: function (res) {
     if (res.code === '0') {
     // console.log(res)
     getXzqhHtml(res.list)
     } else {
     alert(res.msg);
     }

     }
     })*/
}
function openAlwaysUse() {
    pageii = layer.open({
        title: "新增",
        type: 2,
        shadeClose: true,
        fixed: true,
        area: ["700px", "650px"],
        content: baseURL + 'business/alwaysuse.html'
    });
}
/*
 function getXzqhHtml(list) {
 var html = "<ul>" +
 "   <li class='active has-sub'><a href='javascript:checkXzqh(\"\")'>全部</a>";
 html+=getChildrenHtml(list)
 html+= "</li></ul>"
 // console.log(html)
 $("#rectifyChartXzqh").html(html)
 $("#problemChartXzqh").html(html)
 $("#trendChartXzqh").html(html)

 }
 function getChildrenHtml(list) {
 var html=" <ul>    "
 for(var i=0,len=list.length;i<len;i++){

 if(list[i].children.length>0){
 html+=  "     <li class='has-sub'><a href='javascript:checkXzqh("+list[i].xzqhId+")'>"+list[i].name+"</a>" ;
 html+=   getChildrenHtml(list[i].children)
 html+=   "</li>"
 }else{
 html+="  <li><a href='javascript:checkXzqh("+list[i].xzqhId+")'>"+list[i].name+"</a></li>";
 }
 }
 html+="</ul>";
 return html;
 }
 function checkXzqh(id) {debugger

 // getTrendChart(id)
 // getProblemChart(id)
 // getRectifyChart(id)
 // getYearDeptQuestionCount(id)
 }*/

function getAlwaysUse() {
    $.ajax({
        url: '../../../business/alwaysuse/useMenu',
        dataType: 'json',
        type: 'post',
        success: function (res) {
            var data = res.data;
            var html = '';
            if (res.code === '0') {
                for (var i = 0; i < data.length; i++) {
                    html += '<li class="function-item li'+data[i].icon+'">';
                    //html += '<a href="../../../' + data[i].url + '">';//'modules/business/xzzl.html">';
                    html += '<a class="'+data[i].icon+'" href="javascript:parent.alwayUseHref(\'' + data[i].url + '\')">';
                    html += '<span>' + data[i].name + '</span></a>';//指令统计</span></a>';
                    html += '</li>';
                }
                $("#alwaysUse").html(html);
            } else {
                //alert(res.msg);
                console.log(res.msg);
            }
        }
    })
}

function msgDetail(type,id){
	if(type == 'zl'){
		location = '../../business/xzzl.html/' + id
	}else if(type == 'tztb'){
		location = '../../business/tztb.html/' + id
	}
}
var vm = new Vue({
    el: '#homepage',
    data: {
      eczg:'',
      sczg:'',
      allQuestionCount:'0',
      rectifyNum:'0',
      noRectifyNum:'0',
      percentageNum:0,
      xzqhId:1,
      dateType:3
    },
    mounted:function() {
        this.getyearDeptQuestionCount()
        this.getRectifyChart()
    },
    methods: {

        getPercentageNumByClick:function(flag){
            var $this = this;
            console.log(flag)
            switch(flag){
                case 1:
                    if($("#rectify-area-select").val() == -1){
                        $this.xzqhId = 1;
                    }else{
                        $this.xzqhId = $("#rectify-area-select").val();
                    }

                    break;
                case 2:
                    if($("#rectify-area-select-city").val() == -1){
                        $this.xzqhId = $("#rectify-area-select").val();
                    }else{
                        $this.xzqhId = $("#rectify-area-select-city").val();
                    }
                    break;
                case 3:
                    if($("#rectify-area-select-area").val() == -1){
                        $this.xzqhId = $("#rectify-area-select-city").val();
                    }else{
                        $this.xzqhId = $("#rectify-area-select-area").val();
                    }
                    break;
                default:
                    $this.dateType = $("#rectify-date-select").val();
            }
            console.log($this.xzqhId+"===="+$this.dateType)
             $this.getyearDeptQuestionCount(),
             $this.getRectifyChart()
        },
        getyearDeptQuestionCount: function() {
        var $this = this;
            var url = '../business/homeStatistics/yearDeptQuestionCount';
            var params = {};
            params.xzqhId = $this.xzqhId
            //只统计当年整改情况
            params.dateType = 3
            console.log(params)
            $.ajax({
                type: "POST",
                async: false,
                url: baseURL + url,
                contentType: "application/json",
                data: JSON.stringify(params),
                success: function (res) {
                    $this.eczg = ((parseInt(res[0].twoFrequency) * 1.0 / parseInt(res[0].allCount)) * 100).toFixed(2);
                    $this.sczg = ((parseInt(res[0].oneFrequency) * 1.0 / parseInt(res[0].allCount)) * 100).toFixed(2);
                }
            })
        },
        getRectifyChart:function(){
            var $this = this;
            var url = '../business/homeStatistics/rectifyChartSemiRing'
            var params = {};
            //获取日期
            params.dateType = $this.dateType
            params.xzqhId = $this.xzqhId
                //计算总和
            $.ajax({
                type: "POST",
                async: false,
                url: baseURL + url,
                contentType: "application/json",
                data: JSON.stringify(params),
                success: function (res) {
                    $this.allQuestionCount = res[0].allCount;
                    $this.rectifyNum = res[0].rectificationCount;
                    $this.noRectifyNum = res[0].noRectificationCount;
                    if(res[0].allCount != '0'){
                        $this.percentageNum = ((parseInt(res[0].rectificationCount) * 1.0 / parseInt(res[0].allCount)) * 100).toFixed(2)
                    }else{
                        $this.percentageNum = 0
                    }

                }
            })
        }

    }
})

var vm = new Vue({
    el: '#cygn',
    data: {
        types:[],
        memuView:false,
        checkList:[]
    },
    mounted:function() {

    },
    methods: {
        initMemu:function(){
            var $this = this;
            $this.memuView=true;
            $.ajax({
                url : baseURL +'../business/alwaysuse/useMenuChoseList',
                dataType:'json',
                type:'post',
                success: function(res){
                    if(res.code === '0'){
                        $this.types = res.data;
                        console.log($this.types);
                        }
                    }
            });
        },
         saveData:function(){
            var $this = this;
            var menuIds = $this.checkList;
            $.ajax({
                url : baseURL + '../business/alwaysuse/saveData',
                dataType:'json',
                type:'post',
                data:{
                    'menuIds' : menuIds.join(",")
                },
                success: function(res){
                    if(res.code === '0'){
        				getAlwaysUse();
                        $this.memuView=false
                    }else{
                        alert(res.msg);
                    }
                }
            })
        }
    }
})